<template>
    <div class="preferential">
        <div class="title">
            <div class="title-back" @click="onBack"></div>
            <div class="title-text">特色推荐</div>
            <div class="title-share" @click="showShare = true"></div>
        </div>
        <div class="bannerImageUrl">
            <img class="auto-img" :src="bannerImage.bannerImageUrl" alt="">
        </div>
        <div class="hotelType">
            <van-tabs background="#2c23ba" shrink line-height="0px" title-active-color="#5f58ca"
                title-inactive-color="#ddd" v-model:active="active" :ellipsis="false">
                <van-tab title="全部" :click="getAllList">
                    <div class="hotelList" v-for="(item, index) in AllList.content" :key="index">
                        <div class="hotelList-title">
                            <div class="hotelList-img-left">
                                <img class="auto-img" :src="item.imageList[0]">
                            </div>
                            <div class="hotelList-img-right">
                                <div class="hotelList-img-top">
                                    <img class="auto-img" :src="item.imageList[1]">
                                </div>
                                <div class="hotelList-img-bottom">
                                    <img class="auto-img" :src="item.imageList[2]">
                                </div>
                            </div>
                        </div>
                        <div class="hotelList-data">
                            <div>{{ item.shopName }}</div>
                            <p>{{ item.address }}</p>
                            <div class="hotelList-merit">
                                <ul>
                                    <li v-for="(value, index) in item.lableList" :key="index">{{ value }}</li>
                                </ul>
                                <div> <span>￥</span>184<span>起</span> </div>
                            </div>
                        </div>
                    </div>
                </van-tab>
                <van-tab title="特惠推荐">
                    <div class="hotelList" v-for="(item, index) in PreferentialList.content" :key="index">
                        <div class="hotelList-title">
                            <div class="hotelList-img-left">
                                <img class="auto-img" :src="item.imageList[0]">
                            </div>
                            <div class="hotelList-img-right">
                                <div class="hotelList-img-top">
                                    <img class="auto-img" :src="item.imageList[1]">
                                </div>
                                <div class="hotelList-img-bottom">
                                    <img class="auto-img" :src="item.imageList[2]">
                                </div>
                            </div>
                        </div>
                        <div class="hotelList-data">
                            <div>{{ item.shopName }}</div>
                            <p>{{ item.address }}</p>
                            <div class="hotelList-merit">
                                <ul>
                                    <li v-for="(value, index) in item.lableList" :key="index">{{ value }}</li>
                                </ul>
                                <div> <span>￥</span>184<span>起</span> </div>
                            </div>
                        </div>
                    </div>
                </van-tab>
                <van-tab title="品质电竞房" :click="getqualityList">
                    <div class="hotelList" v-for="(item, index) in qualityList.content" :key="index">
                        <div class="hotelList-title">
                            <div class="hotelList-img-left">
                                <img class="auto-img" :src="item.imageList[0]">
                            </div>
                            <div class="hotelList-img-right">
                                <div class="hotelList-img-top">
                                    <img class="auto-img" :src="item.imageList[1]">
                                </div>
                                <div class="hotelList-img-bottom">
                                    <img class="auto-img" :src="item.imageList[2]">
                                </div>
                            </div>
                        </div>
                        <div class="hotelList-data">
                            <div>{{ item.shopName }}</div>
                            <p>{{ item.address }}</p>
                            <div class="hotelList-merit">
                                <ul>
                                    <li v-for="(value, index) in item.lableList" :key="index">{{ value }}</li>
                                </ul>
                                <div> <span>￥</span>184<span>起</span> </div>
                            </div>
                        </div>
                    </div>
                </van-tab>
            </van-tabs>
        </div>

        <!-- 分享 -->
        <van-share-sheet v-model:show="showShare" title="立即分享给好友" :options="options" @select="onSelect" />
    </div>
</template>

<script setup lang="ts">

import { useRoute } from 'vue-router'
import { reactive, onMounted, ref } from 'vue'
import { getPreferentialRecommendation, getQualityRoom, getFeatureRecommendation, getAllRoom } from '@/api/api'
import type { bannerImage, PreferentialListTpye } from '@/tsList/homeFunts'
import { useRouter } from 'vue-router'


const bannerImage = reactive<bannerImage>({
    bannerImageUrl: ''
})
let router = useRouter();

const showShare = ref(false)
const options = [
    { name: '微信', icon: 'wechat' },
    { name: '微博', icon: 'weibo' },
    { name: '复制链接', icon: 'link' },
    { name: '分享海报', icon: 'poster' },
    { name: '二维码', icon: 'qrcode' },
];

//选择 全部/特惠/品质电竞房
const active = ref(1);
//特惠推荐列表
const PreferentialList = reactive<PreferentialListTpye>({
    content: [],
    totalElements: 45,
    totalPages: 5
});
//全部列表
const AllList = reactive<PreferentialListTpye>({
    content: [],
    totalElements: 45,
    totalPages: 5
});
//品质电竞房列表
const qualityList = reactive<PreferentialListTpye>({
    content: [],
    totalElements: 45,
    totalPages: 5
});

function onBack() {
    router.go(-1)
}
function getAllList() {
    console.log('这是全部')
}

function getqualityList() {
    console.log('这是品质电竞房')
}
//分享
const onSelect = () => {
    showShare.value = false;
};

onMounted(() => {
    let route = useRoute()
    console.log('route.path', route.path);


    //获取特色推荐的首页
    getFeatureRecommendation().then((res) => {
        console.log('特色推荐的首页', res.data);
        bannerImage.bannerImageUrl = res.data.bannerImageUrl
    })

    let num = route.query.num as string;
    if (num == '0') {
        //把导航切到相应的地方
        active.value = 1

        //获取特惠推荐
        getPreferentialRecommendation().then((res) => {
            // console.log('特惠推荐', res);
            PreferentialList.content = res.data.content
        })
        //获取品质电竞房
        getQualityRoom().then((res) => {
            // console.log('品质电竞房', res);
            qualityList.content = res.data.content
        })
        //获取全部
        getAllRoom().then((res) => {
            // console.log('品质电竞房', res);
            AllList.content = res.data.content
        })
    } else {
        //把导航切到相应的地方
        active.value = 2

        //获取品质电竞房
        getQualityRoom().then((res) => {
            // console.log('品质电竞房', res);
            qualityList.content = res.data.content
        })
        //获取特惠推荐
        getPreferentialRecommendation().then((res) => {
            // console.log('特惠推荐', res);
            PreferentialList.content = res.data.content
        })
        //获取全部
        getAllRoom().then((res) => {
            // console.log('品质电竞房', res);
            AllList.content = res.data.content
        })
    }
})

</script>

<style lang="less" scoped>
.auto-img {
    width: 100%;
    height: 100%;
    display: block;
}

.preferential {
    min-height: 100vh;
    background-color: #2c23ba;

    .title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 40px;
        padding: 10px 10px;
        background-color: white;
        color: black;
        font-weight: 600;
        font-size: 16px;
        position: fixed;
        top: -1px;
        left: 0;
        right: 0;
        z-index: 9;

        .title-back {
            width: 15px;
            height: 20px;
            background-image: url('@/assets/icon/tme_ad_video_top_back.png');
            background-size: cover;
        }

        .title-share {
            width: 16px;
            height: 15px;
            background-image: url('@/assets/icon/T0.png');
            background-size: cover;
        }
    }

    .bannerImageUrl {
        height: 135px;
        margin-top: 40px;
        margin-bottom: -1px;
    }

    .hotelType {
        padding: 10px 10px;

        /deep/ .van-tab__text {
            font-size: 12px;
            background-color: #4e46c5;
            padding: 5px 10px;
            border-radius: 999px;
            transform: scale(.9);
            transform-origin: 0 0;
        }

        // /deep/.van-tab--grow {
        //     padding: 0;
        // }
        /deep/.van-tab--shrink {
            padding: 0 2px;
        }

        /deep/.van-tab--active .van-tab__text {
            background-color: white;
            border-radius: 999px;
        }

        .hotelList {
            // width: 100%;
            height: 185px;
            background-color: white;
            border-radius: 5px;
            overflow: hidden;
            margin-bottom: 10px;

            .hotelList-title {
                height: 105px;
                width: 100%;
                display: flex;
                justify-content: space-between;

                .hotelList-img-left {
                    height: 100%;
                    width: 59%;
                }

                .hotelList-img-right {
                    height: 100%;
                    width: 40%;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;

                    .hotelList-img-top {
                        height: 49%;
                        width: 100%;
                    }

                    .hotelList-img-bottom {
                        height: 49%;
                        width: 100%;
                    }
                }
            }

            .hotelList-data {
                padding: 0 10px;
                font-size: 13px;
                font-weight: 600;
                padding-top: 5px;
                color: black;

                p {
                    font-size: 12px;
                    color: #989898;
                    transform: scale(.8);
                    transform-origin: 0 0;
                }

                .hotelList-merit {
                    height: 28px;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    ul {
                        width: 270px;
                        white-space: nowrap;
                        overflow: hidden;
                        display: flex;
                        align-items: center;

                        li {
                            font-size: 12px;
                            font-weight: 400;
                            padding: 0 2px;
                            transform: scale(.8);
                            border: 1px solid #ddd;
                        }
                    }

                    div {
                        font-size: 18px;
                        color: #f07b22;
                        font-weight: 600;

                        span {
                            font-size: 12px;
                            font-weight: 400;
                            // transform: scale(.8);
                        }
                    }
                }
            }
        }
    }
}
</style>